package com.mashibing.strategy.filter.impl;

import com.mashibing.common.constant.CacheConstant;
import com.mashibing.common.model.StandardSubmit;
import com.mashibing.strategy.client.BeaconCacheClient;
import com.mashibing.strategy.filter.StrategyFilter;
import com.mashibing.strategy.util.DFAUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

/**
 * @author SNA
 * @date 2025/8/25
 * @Description  用DFA算法进行敏感词校验
 **/
@Service(value = "dfaDirtyWord")
@Slf4j
public class DirtyWordDFAStrategyFilter implements StrategyFilter {


    @Override
    public void strategy(StandardSubmit submit) {
        log.info("【策略模块-敏感词校验】   校验ing.........");

        //1、获取短信内容
        String text = submit.getText();

        //2、调用DFA查看敏感词
        Set<String> dirtyWords = DFAUtil.getDirtyWord(text);

        //3、根据返回的set集合，判断是否包含敏感词
        if (dirtyWords != null && dirtyWords.size() > 0) {
            //4、如果有敏感词，抛出异常 或者 其他操作。。
            log.info("【策略模块-敏感词校验】  短信内容包含敏感词信息，dirtyWords = {}", dirtyWords);
            // 还需要做其他处理

        }
    }
}
